package com.wutong.resonance.model.audio.math;

import lombok.Getter;
import lombok.Setter;

/**
 * 复数类
 * @author wutong
 */
@Getter
@Setter
public class Complex {
    // 实部
    private final double re;
    // 虚部
    private final double im;

    public Complex(double real, double imag) {
        re = real;
        im = imag;
    }

    public Complex plus(Complex b) {
        return new Complex(this.re + b.re, this.im + b.im);
    }

    public Complex minus(Complex b) {
        return new Complex(this.re - b.re, this.im - b.im);
    }

    public Complex times(Complex b) {
        return new Complex(
                this.re * b.re - this.im * b.im,
                this.re * b.im + this.im * b.re);
    }
}
